#!/bin/bash
FACTOR=$2
if [ $# -eq 2 ]
then
	awk -v fact=$FACTOR -F"	" 'BEGIN{count=1;factor=fact;k=1;orig[0]="0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0"} {orig[k]=$1 "\t" $2 "\t" $3 "\t" $4 "\t" $5 "\t" $6 "\t" $7 ;sum2=sum2+$2;sum3=sum3+$3;sum4=sum4+$4;sum5=sum5+$5;sum6=sum6+$6;sum7=sum7+$7;if(count==factor){split(orig[k-factor],sp,"\t");sum2=sum2-sp[2];sum3=sum3-sp[3];sum4=sum4-sp[4];sum5=sum5-sp[5];sum6=sum6-sp[6];sum7=sum7-sp[7];printf("%s\t%.2f\t%.2f\t%d\t%d\t%.2f\t%.2f\n",$1,sum2/factor,sum3/factor,sum4/factor,sum5/factor,sum6/factor,sum7/factor);}else{count=count+1;}k=k+1;}' $1;
else
	echo "Usage: ./format.sh [Input File] [Moving Average Factor]"
fi
